package com.zhaojk.audio.util;

import cn.hutool.core.date.TimeInterval;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class TimeTraceAspect {
    @Around("@annotation(timeTrace)")
    public Object logTime(ProceedingJoinPoint joinPoint, TimeTrace timeTrace) throws Throwable {
        String methodName = joinPoint.getSignature().toShortString();
        String tag = timeTrace.value().isEmpty() ? methodName : timeTrace.value();

        TimeInterval timer = new TimeInterval();
        Object result = joinPoint.proceed();

        System.out.printf("[%s] 执行耗时: %s ms\n", tag, timer.intervalMs());
        return result;
    }
}
